package com.yc.baseapi;



/**
 * jvm关闭时的钩子
 * RunTime.getRunTime().addShutdownHook
 */
public class TestShutdownHook {
    public static void main(String[] args) {
        //新建一个进程
        Thread t = new Thread(()-> {
            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println("TestShutdownHook_.......");
        }, "yc_TestShutdownHook");
        Runtime.getRuntime().addShutdownHook(t);
        try {
            Thread.sleep(120000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }

}
